package org.finesys.chat.core.base.document;

import org.finesys.chat.core.base.segment.TextSegment;

import java.util.Objects;

public class Document {

    private String text;
    private Metadata metadata;

    public Document(String text, Metadata metadata) {
        this.text = text;
        this.metadata = metadata;
    }

    public String getText() {
        return text;
    }

    public Metadata getMetadata() {
        return metadata;
    }

    public TextSegment toTextSegment() {
        return TextSegment.from(text, this.metadata.copy().put("index", "0"));
    }


    public static Document from(String text, Metadata metadata) {
        return new Document(text, metadata);
    }

    public static Document from(String text) {
        return new Document(text, new Metadata());
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) return true;
        if (object == null || getClass() != object.getClass()) return false;
        Document document = (Document) object;
        return Objects.equals(text, document.text) && Objects.equals(metadata, document.metadata);
    }

    @Override
    public int hashCode() {
        return Objects.hash(text, metadata);
    }

    @Override
    public String toString() {
        return "Document{" +
                "text='" + text + '\'' +
                ", metadata=" + metadata +
                '}';
    }
}
